﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;

namespace BLL
{
    public class UserBUO:IBUO<tbl_DangNhap>
    {
        CSDLBanHangDataContext context = new CSDLBanHangDataContext();
        public bool Insert(tbl_DangNhap obj)
        {
            throw new NotImplementedException();
        }

        public bool Delete(String id)
        {
            throw new NotImplementedException();
        }

        public bool Delete(tbl_DangNhap obj)
        {
            throw new NotImplementedException();
        }

        public List<tbl_DangNhap> GetAll()
        {
            return context.tbl_DangNhaps.ToList<tbl_DangNhap>();
        }

        public tbl_DangNhap GetSingle(String username)
        {
            return context.tbl_DangNhaps.Where(n => n.userName.Equals(username)).ToList<tbl_DangNhap>().FirstOrDefault();
        }

        public bool Update(String id, tbl_DangNhap obj)
        {
            throw new NotImplementedException();
        }

        public bool CheckUser(string user, string pass)
        {
            var t = context.tbl_DangNhaps.Where(n => n.userName.ToString().Equals(user) && n.password.ToString().Trim().Equals(MaHoaMD5.EncryptMD5(pass))).ToList();
            return t.Count == 1 ? true : false;
        }

        public String ThongTinDangNhap(string idnhanvien)
        {
            return context.tbl_DangNhaps.Where(p => p.id_NhanVien.Equals(idnhanvien)).Select(n => n.Quyen).FirstOrDefault();
        }
    }
}
